package com.ciccwm.core.util;

import com.ciccwm.core.exception.BusinessException;
import com.ciccwm.core.response.ResultCode;
import org.apache.commons.lang3.StringUtils;

/**
 * 断言工具类.
 * 提供常用的断言方法，用于参数校验和业务逻辑验证.
 *
 * @author ciccwm
 */
public final class Assert {
    private Assert() {
        throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
    }

    /**
     * 断言对象不为空.
     *
     * @param object 待检查对象
     * @param message 错误消息
     * @throws ValidationException 如果对象为空
     */
    public static void notNull(Object object, String message) {
        if (object == null) {
            throw new BusinessException(ResultCode.VALIDATE_FAILED, message);
        }
    }

    /**
     * 断言字符串不为空.
     *
     * @param text 待检查字符串
     * @param message 错误消息
     * @throws ValidationException 如果字符串为空
     */
    public static void notEmpty(String text, String message) {
        if (StringUtils.isEmpty(text)) {
            throw new BusinessException(ResultCode.VALIDATE_FAILED, message);
        }
    }

    /**
     * 断言表达式为真.
     *
     * @param expression 待检查表达式
     * @param message 错误消息
     * @throws BusinessException 如果表达式为假
     */
    public static void isTrue(boolean expression, String message) {
        if (!expression) {
            throw new BusinessException(ResultCode.VALIDATE_FAILED, message);
        }
    }

    /**
     * 断言表达式为真.
     *
     * @param expression 待检查表达式
     * @param resultCode 结果码
     * @throws BusinessException 如果表达式为假
     */
    public static void isTrue(boolean expression, ResultCode resultCode) {
        if (!expression) {
            throw new BusinessException(resultCode);
        }
    }

    /**
     * 断言条件为假.
     *
     * @param condition 条件
     * @param message 错误消息
     */
    public static void isFalse(boolean condition, String message) {
        if (condition) {
            throw new BusinessException(ResultCode.VALIDATE_FAILED, message);
        }
    }
} 
